<include file="DormChange:header"/>
<body>
<div class="wraper">
    <div class="load">
        <img class="load-bee" src="/assets/base/dormchange/images/load-bee.png">
    </div>
	<div class="head clearfix">
		<a href="javascript:history.go(-1);" class="iconfont icon-zuo pull-left"></a>
		<span class="head-name pull-left">调换申请</span>
		<a href="{BEESCRM::U('/Base/DormChange/index',array('wechat_id'=>$wechat_id))}" class="iconfont icon-shouye pull-left text-right"></a>
	</div>
	<p class="field">请选择调换至</p>
	<p class="form-box">
		<select class="select" id="community_id" onchange="getBuilding();">
			<option value=''>请选择园区</option>
			<volist name="community" id="vo">
			<option value="{BEESCRM:$vo['community_id']}">{BEESCRM:$vo['community_name']}</option>
			</volist>
		</select>
		<span class="triangle"></span>
	</p>
	<p class="form-box">
		<select class="select" id="building_id" onchange="getDorm();">
			<option value=''>请选择楼幢</option>
		</select>
		<span class="triangle"></span>
	</p>
	<p class="form-box">
		<select class="select" id="dorm_id">
			<option value=''>请选择宿舍</option>
		</select>
		<span class="triangle"></span>
	</p>
	<div class="btn-box half-btn">
		<a href="#" class="btn" id="submit">申请调换</a>
		<a href="javascript:history.go(-1);" class="btn white-btn">取消返回</a>
	</div>
	<div class="bottom-box">
		<p class="copyright">杭州青橄榄网络技术有限公司 技术支持</p>
	</div>
</div>
<include file="DormChange:commonJs"/>
<script>
	var height = $(document).height();
	var bottombox_height = $('.bottom-box').outerHeight();
	$('.wraper').css("minHeight",height);
	$('.logistics').css("paddingBottom",bottombox_height);


	$(function(){
		var height = $(document).height();
		var height_head = $('.head').outerHeight();
		var contain_h = height - height_head;
		$('.logistics').css("minHeight",contain_h);
	});

	$(window).load(function(){
		$('.load').hide();
	});
	//获取楼幢
	function getBuilding(){
		var community_id = $('#community_id').val();
		$.ajax({
			type:'post',
			data:{'community_id':community_id},
			url:'/Base/DormChange/getBuilding',
			dataType:'json',
			success:function(data){
				if(data.status == 'S'){
					$('#building_id').html("<option value=''>请选择楼幢</option>");
					$('#dorm_id').html("<option value=''>请选择宿舍</option>");
					var html = '';
					$.each(data.data,function(i,item){
						html += "<option value='"+ item.building_id +"'>"+ item.building_name +"</option>";
					});
					$('#building_id').append(html);
				}else{
					$('#building_id').html("<option value=''>请选择楼幢</option>");
					$('#dorm_id').html("<option value=''>请选择宿舍</option>");
				}
			}
		});
	}
	//获取宿舍
	function getDorm(){
		var building_id = $('#building_id').val();
		$.ajax({
			type:'post',
			data:{'building_id':building_id},
			url:'/Base/DormChange/getDorm',
			dataType:'json',
			success:function(data){
				if(data.status == 'S'){
					$('#dorm_id').html("<option value=''>请选择宿舍</option>");
					var html = '';
					$.each(data.data,function(i,item){
						html += "<option value='"+ item.dorm_id +"'>"+ item.dorm_name +"</option>";
					});
					$('#dorm_id').append(html);
				}else{
					$('#dorm_id').html("<option value=''>请选择宿舍</option>");
				}
			},
			error:function(){
				$.alert('error','通讯错误');
			},
		});
	}
	
	//提交数据
	$('#submit').click(function(){
		var to_community_id = $('#community_id').val();
		var to_building_id = $('#building_id').val();
		var to_dorm_id = $('#dorm_id').val();
		if(!to_community_id){
			$.alert('error','请选择园区');return ;
		}
		if(!to_building_id){
			$.alert('error','请选择楼幢');return ;
		}
		if(!to_dorm_id){
			$.alert('error','请选择宿舍');return ;
		}
		$.ajax({
			type:'post',
			data:{'to_building_id':to_building_id,'to_dorm_id':to_dorm_id},
			url:'/Base/DormChange/createRecord',
			dataType:'json',
			success: function(data){
				if(data.status == 'S'){
					$.alert('success',data.message);
					setTimeout(function(){
						location.href = data.url;
					},3000);
				}else {
					$.alert('error',data.message);
				}
			},
			error: function(){
				$.alert('error','通讯错误');
			},
		});
		//var url = '{BEESCRM::U('/Base/DormChange/createRecord',array('wechat_id'=>$wechat_id))}/to_dorm_id/'+ to_dorm_id;
		//location.href = url;
	});
</script>
</body>
</html>